﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml; //要使用XmlReader对象，就需要先引入System.Xml命名空间

namespace WEEK10_LAB01
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string filePath = Server.MapPath("汽车.xml");

                XmlReader reader = XmlReader.Create(filePath);

                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element) //如果当前节点是起始元素
                    {
                        if (reader.Name == "品牌") //如果当前节点的名称为“品牌”
                        {
                            reader.Read(); //读取下一个节点
                            lblBrand.Text = reader.Value; //使用ReadInnerXml读取包括标志在内的所有内容
                        }
                        else if (reader.Name == "车主")
                        {
                            if (reader.HasAttributes) //如果当前节点有属性
                            {
                                lblNumber.Text = reader.GetAttribute("车牌号"); //得到“车牌号”属性的值
                            }
                            reader.Read();
                            lblOwnner.Text = reader.Value;
                        }
                        else if (reader.Name == "保险公司")
                        {
                            reader.Read();
                            lblInsurance.Text = reader.Value;
                        }
                        else if (reader.Name == "银行贷款")
                        {
                            reader.Read();
                            lblBankType.Text = reader.Name;
                            reader.Read();
                            lblBankName.Text = reader.Value;
                        }
                        else if (reader.Name == "维修地点")
                        {
                            reader.Read();
                            lblRepairPlace.Text = reader.Value;
                        }
                        else
                        {
                        }
                    }
                }
                reader.Close();
            }
            catch (Exception exception)
            {
                Response.Write(exception.Message);
            }
        }
    }
}